home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Development / Source / AutoBin Source / DSUserProcs.c < prev    next >
Text File  |  1993-12-09  |  8KB  |  250 lines

  1. /******************************************************************************
  2. **
  3. **  Project Name:    DropShell
  4. **     File Name:    DSUserProcs.c
  5. **
  6. **   Description:    Specific AppleEvent handlers used by the DropBox
  7. **
  8. *******************************************************************************
  9. **                       A U T H O R   I D E N T I T Y
  10. *******************************************************************************
  11. **
  12. **    Initials    Name
  13. **    --------    -----------------------------------------------
  14. **    LDR            Leonard Rosenthol
  15. **    MTC            Marshall Clow
  16. **    SCS            Stephan Somogyi
  17. **
  18. *******************************************************************************
  19. **                      R E V I S I O N   H I S T O R Y
  20. *******************************************************************************
  21. **
  22. **      Date        Time    Author    Description
  23. **    --------    -----    ------    ---------------------------------------------
  24. **    01/25/92            LDR        Removed the use of const on the userDataHandle
  25. **    12/09/91            LDR        Added the new SelectFile userProc
  26. **                                Added the new Install & DisposeUserGlobals procs
  27. **                                Modified PostFlight to only autoquit on odoc, not pdoc
  28. **    11/24/91            LDR        Added the userProcs for pdoc handler
  29. **                                Cleaned up the placement of braces
  30. **                                Added the passing of a userDataHandle
  31. **    10/29/91            SCS        Changes for THINK C 5
  32. **    10/28/91            LDR        Officially renamed DropShell (from QuickShell)
  33. **                                Added a bunch of comments for clarification
  34. **    10/06/91    00:02    MTC        Converted to MPW C
  35. **    04/09/91    00:02    LDR        Added to Projector
  36. **
  37. ******************************************************************************/
  38.  
  39.  
  40. #include "DSGlobals.h"
  41. #include "DSUserProcs.h"
  42. #include "binhex.h"
  43. /*
  44.     This routine is called during init time.
  45.     
  46.     It allows you to install more AEVT Handlers beyond the standard four
  47. */
  48. #pragma segment Main
  49. pascal void InstallOtherEvents (void) {
  50. }
  51.  
  52.  
  53. /*    
  54.     This routine is called when an OAPP event is received.
  55.     
  56.     Currently, all it does is set the gOApped flag, so you know that
  57.     you were called initally with no docs, and therefore you shouldn't 
  58.     quit when done processing any following odocs.
  59. */
  60. #pragma segment Main
  61. pascal void OpenApp (void) {
  62.     gOApped = true;
  63. }
  64.  
  65.  
  66. /*    
  67.     This routine is called when an QUIT event is received.
  68.     
  69.     We simply set the global done flag so that the main event loop can
  70.     gracefully exit.  We DO NOT call ExitToShell for two reasons:
  71.     1) It is a pretty ugly thing to do, but more importantly
  72.     2) The Apple event manager will get REAL upset!
  73. */
  74. #pragma segment Main
  75. pascal void QuitApp (void) {
  76.     gDone = true;    /*    All Done! */
  77. }
  78.  
  79.  
  80. /*    
  81.     This routine is the first one called when an ODOC or PDOC event is received.
  82.     
  83.     In this routine you would place code used to setup structures, etc. 
  84.     which would be used in a 'for all docs' situation (like "Archive all
  85.     dropped files")
  86.  
  87.     Obviously, the opening boolean tells you whether you should be opening
  88.     or printing these files based on the type of event recieved.
  89.     
  90.     userDataHandle is a handle that you can create & use to store your own
  91.     data structs.  This dataHandle will be passed around to the other 
  92.     odoc/pdoc routines so that you can get at your data without using
  93.     globals - just like the new StandardFile.  
  94.     
  95.     We also return a boolean to tell the caller if you support this type
  96.     of event.  By default, our dropboxes don't support the pdoc, so when
  97.     opening is FALSE, we return FALSE to let the caller send back the
  98.     proper error code to the AEManager.
  99.  
  100.     You will probably want to remove the #pragma unused (currently there to fool the compiler!)
  101. */
  102. #pragma segment Main
  103. pascal Boolean PreFlightDocs (Boolean opening, Handle *userDataHandle) {
  104. #pragma unused ( userDataHandle )
  105.  
  106.     return opening;        // we support opening, but not printing - see above
  107. }
  108.  
  109.  
  110. /*    
  111.     This routine is called for each file passed in the ODOC event.
  112.     
  113.     In this routine you would place code for processing each file/folder/disk that
  114.     was dropped on top of you.
  115.     
  116.     You will probably want to remove the #pragma unused (currently there to fool the compiler!)
  117. */
  118. #pragma segment Main
  119.  
  120. //--------------------------------------------------------
  121.     void CopyPascalString(StringPtr src,StringPtr dst)
  122. //--------------------------------------------------------
  123. {
  124.     BlockMove(src,dst,src[0]+1);
  125. }
  126.  
  127. //--------------------------------------------------------
  128.     void CatPascalString(StringPtr dst,StringPtr src)
  129. //--------------------------------------------------------
  130. {
  131.     short     srclen = src[0],
  132.             dstlen = dst[0];
  133.     
  134.     if (srclen + dstlen > 256 )
  135.         srclen = (256 - dstlen);
  136.  
  137.     BlockMove(&src[1],&dst[dstlen + 1],srclen);
  138.     dstlen +=srclen;
  139.     dst[0]=dstlen;
  140. }
  141.  
  142. pascal void OpenDoc ( FSSpecPtr myFSSPtr, Boolean opening, Handle userDataHandle ) {
  143. //#pragma unused ( myFSSPtr )
  144. //#pragma unused ( opening )
  145. //#pragma unused ( userDataHandle )
  146.     
  147.     Str255 fileName;
  148.     short oe;
  149.     extern short gRefNum;
  150.     char len;
  151.     
  152.     CopyPascalString(myFSSPtr->name,fileName);
  153.     CatPascalString(fileName,"\p.hqx");
  154.     
  155.     
  156.     HCreate(myFSSPtr->vRefNum,myFSSPtr->parID,fileName,'R*ch','TEXT');
  157.     oe = HOpen(myFSSPtr->vRefNum,myFSSPtr->parID,fileName,fsRdWrPerm,&gRefNum);
  158.     oe = SetEOF(gRefNum,0);                //reset it to 0 if not already
  159.     
  160.     if (oe == noErr) {
  161.         SendBinHex(myFSSPtr->vRefNum,myFSSPtr->parID,myFSSPtr->name);
  162.         
  163.         FSClose(gRefNum);
  164.         FlushVol(nil,myFSSPtr->vRefNum);
  165.     }
  166.  
  167. }
  168.  
  169.  
  170. /*    
  171.     This routine is the last routine called as part of an ODOC event.
  172.     
  173.     In this routine you would place code to process any structures, etc. 
  174.     that you setup in the PreflightDocs routine.
  175.  
  176.     If you created a userDataHandle in the PreFlightDocs routines, this is
  177.     the place to dispose of it since the Shell will NOT do it for you!
  178.     
  179.     You will probably want to remove the #pragma unusued (currently there to fool the compiler!)
  180. */
  181. #pragma segment Main
  182. pascal void PostFlightDocs ( Boolean opening, Handle userDataHandle ) {
  183. #pragma unused ( opening )
  184. #pragma unused ( userDataHandle )
  185.  
  186.     if ( (opening) && (!gOApped) )
  187.         gDone = true;    //    close everything up!
  188.  
  189.     /*
  190.         The reason we do not auto quit is based on a recommendation in the
  191.         Apple event Registry which specifically states that you should NOT
  192.         quit on a 'pdoc' as the Finder will send you a 'quit' when it is 
  193.         ready for you to do so.
  194.     */
  195. }
  196.  
  197.  
  198. /*
  199.     This routine is called when the user chooses "Select File…" from the
  200.     File Menu.
  201.     
  202.     Currently it simply calls the new StandardGetFile routine to have the
  203.     user select a single file (any type, numTypes = -1) and then calls the
  204.     SendODOCToSelf routine in order to process it.  
  205.             
  206.     The reason we send an odoc to ourselves is two fold: 1) it keeps the code
  207.     cleaner as all file openings go through the same process, and 2) if events
  208.     are ever recordable, the right things happen (this is called Factoring!)
  209.  
  210.     Modification of this routine to only select certain types of files, selection
  211.     of multiple files, and/or handling of folder & disk selection is left 
  212.     as an exercise to the reader.
  213. */
  214. pascal void SelectFile (void)
  215. {
  216.     StandardFileReply    stdReply;
  217.     SFTypeList            theTypeList;
  218.  
  219.     StandardGetFile(NULL, -1, theTypeList, &stdReply);
  220.     if (stdReply.sfGood)    // user did not cancel
  221.         SendODOCToSelf(&stdReply.sfFile);    // so send me an event!
  222. }
  223.  
  224. /*
  225.     This routine is called during the program's initialization and gives you
  226.     a chance to allocate or initialize any of your own globals that your
  227.     dropbox needs.
  228.     
  229.     You return a boolean value which determines if you were successful.
  230.     Returning false will cause DropShell to exit immediately.
  231. */
  232. pascal Boolean InitUserGlobals(void)
  233. {
  234.     NewLine[0]=1;
  235.     NewLine[1]=13;
  236.     NewLine[2]=0;
  237.     return(true);    // nothing to do, it we must be successful!
  238.     
  239. }
  240.  
  241. /*
  242.     This routine is called during the program's cleanup and gives you
  243.     a chance to deallocate any of your own globals that you allocated 
  244.     in the above routine.
  245. */
  246. pascal void DisposeUserGlobals(void)
  247. {
  248.     // nothing to do for our sample dropbox
  249. }
  250.